package com.ruoyi.projectplan.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.projectplan.domain.XzkProjectPlan;
import com.ruoyi.projectplan.service.IXzkProjectPlanService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目计划Controller
 * 
 * @author ruoyi
 * @date 2021-04-02
 */
@Controller
@RequestMapping("/projectplan/projectplan")
public class XzkProjectPlanController extends BaseController
{
    private String prefix = "projectplan/projectplan";

    @Autowired
    private IXzkProjectPlanService xzkProjectPlanService;

    @RequiresPermissions("projectplan:projectplan:view")
    @GetMapping()
    public String projectplan()
    {
        return prefix + "/projectplan";
    }

    /**
     * 查询项目计划列表
     */
    @RequiresPermissions("projectplan:projectplan:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(XzkProjectPlan xzkProjectPlan)
    {
        startPage();
        List<XzkProjectPlan> list = xzkProjectPlanService.selectXzkProjectPlanList(xzkProjectPlan);
        return getDataTable(list);
    }

    /**
     * 导出项目计划列表
     */
    @RequiresPermissions("projectplan:projectplan:export")
    @Log(title = "项目计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(XzkProjectPlan xzkProjectPlan)
    {
        List<XzkProjectPlan> list = xzkProjectPlanService.selectXzkProjectPlanList(xzkProjectPlan);
        ExcelUtil<XzkProjectPlan> util = new ExcelUtil<XzkProjectPlan>(XzkProjectPlan.class);
        return util.exportExcel(list, "projectplan");
    }

    /**
     * 新增项目计划
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存项目计划
     */
    @RequiresPermissions("projectplan:projectplan:add")
    @Log(title = "项目计划", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(XzkProjectPlan xzkProjectPlan)
    {
        return toAjax(xzkProjectPlanService.insertXzkProjectPlan(xzkProjectPlan));
    }

    /**
     * 修改项目计划
     */
    @GetMapping("/edit/{planid}")
    public String edit(@PathVariable("planid") Long planid, ModelMap mmap)
    {
        XzkProjectPlan xzkProjectPlan = xzkProjectPlanService.selectXzkProjectPlanById(planid);
        mmap.put("xzkProjectPlan", xzkProjectPlan);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目计划
     */
    @RequiresPermissions("projectplan:projectplan:edit")
    @Log(title = "项目计划", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(XzkProjectPlan xzkProjectPlan)
    {
        return toAjax(xzkProjectPlanService.updateXzkProjectPlan(xzkProjectPlan));
    }

    /**
     * 删除项目计划
     */
    @RequiresPermissions("projectplan:projectplan:remove")
    @Log(title = "项目计划", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(xzkProjectPlanService.deleteXzkProjectPlanByIds(ids));
    }
}
